package com.itcast.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.HashMap;
import java.util.Map;

public class ResponseBodyUtil {
    private static ObjectMapper mapper = new ObjectMapper();
    public static String getSuccess(Object object,String str) throws Exception {
        Map<String,Object> map = new HashMap<>();
        map.put("data",object);
        map.put("msg",str+"成功");
        map.put("code",200);
        return mapper.writeValueAsString(map);
    }
    public static String getUnSuccess(Object object,String str) throws Exception {
        Map<String,Object> map = new HashMap<>();
        map.put("data",object);
        map.put("msg",str+"失败");
        map.put("code",400);
        return mapper.writeValueAsString(map);
    }

    public static String getSuccessNoObject(String str) throws Exception {
        Map<String,Object> map = new HashMap<>();
        map.put("msg",str+"成功");
        map.put("code",200);
        return mapper.writeValueAsString(map);
    }

    public static String getUnSuccessNoObject(String str) throws Exception {
        Map<String,Object> map = new HashMap<>();
        map.put("msg",str+"失败");
        map.put("code",400);
        return mapper.writeValueAsString(map);
    }
}
